#!/bin/bash

# Copyright © Los Alamos National Security, LLC, and others.

. ./environment.sh

cd $DATADIR
ln -s $QUACBASE/tests/standalone/wp-access/raw .

LIMIT=5
WP_TSUPDATE="wp-tsupdate --warn-duplicates --limit=$LIMIT"

echo
echo '*** Warning -- bad globbing gives multiple months'
z $WP_TSUPDATE data raw/2012/2012-10/pagecounts-20121001-*.gz

echo
echo '*** Strategy 1 -- first update of month (one day)'
x rm -Rf data
z $WP_TSUPDATE data \
    $(ls raw/2012/2012-10/pagecounts-20121001-*.gz | tail -n +2) \
    raw/2012/2012-10/pagecounts-20121002-000000.gz
x ts-dump data

echo
echo '*** Strategy 0 -- first ~29 days'
z $WP_TSUPDATE data \
    $(ls raw/2012/2012-10/pagecounts-201210[012]*.gz | tail -n +2)
x ts-dump data

echo
echo '*** Strategy 2 -- close out month (2 days + 1 hour)'
z $WP_TSUPDATE --prune data raw/2012/2012-10/pagecounts-2012103*.gz \
                            raw/2012/2012-11/pagecounts-20121101-000000.gz
x ts-dump data

echo
echo '*** Strategy 3 -- bulk load a whole month'
x rm -Rf data
z $WP_TSUPDATE --prune data $(ls raw/2012/2012-10/*.gz | tail -n +2) \
                            raw/2012/2012-11/pagecounts-20121101-000000.gz
x ts-dump data

echo
echo '*** Validate modification times'
stat data/* | fgrep Modify: | sed -E 's/[0-9]{6} / /' > mtime.dataset
stat raw/2012/2012-10/pagecounts-201210* raw/2012/2012-11/pagecounts-20121101-000000.gz | fgrep Modify: | sed -E 's/[0-9]{6} / /' | tail -1 > mtime.input
diff -u mtime.input mtime.dataset
